package com.hd123.rumba.qt.def;

import java.util.ArrayList;
import java.util.List;

public class SQLCheckList {

  /**
   * 返回适用于where或having的条件子句
   * 
   * @return
   */
  public String getSQLClause() {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < getCaptions().size(); ++i) {
      if ("yes".equals((String) getCheckeds().get(i))
          && !((String) getExpressions().get(i)).startsWith(":")) {
        if (sb.length() != 0)
          sb.append(getAndOr());
        sb.append(" (");
        sb.append(getExpressions().get(i));
        sb.append(") ");
      }
    }
    return sb.length() == 0 ? null : sb.toString();
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer();
    sb.append(getClass().getName() + "\n");
    sb.append("AndOr: " + getAndOr() + "\n");
    sb.append("Captions: " + getCaptions() + "\n");
    sb.append("Expressions: " + getExpressions() + "\n");
    sb.append("Checkeds: " + getCheckeds() + "\n");
    return sb.toString();
  }

  private String andOr;

  private List captions = new ArrayList(); // list of String

  private List expressions = new ArrayList(); // list of String

  private List checkeds = new ArrayList(); // list of String

  public List getCaptions() {
    return captions;
  }

  public void setCaptions(List captions) {
    this.captions = captions;
  }

  public List getCheckeds() {
    return checkeds;
  }

  public void setCheckeds(List checkeds) {
    this.checkeds = checkeds;
  }

  public List getExpressions() {
    return expressions;
  }

  public void setExpressions(List expressions) {
    this.expressions = expressions;
  }

  public String getAndOr() {
    return andOr;
  }

  public void setAndOr(String andor) {
    this.andOr = andor;
  }

}
